﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Data.SqlClient;

namespace FinallyWork
{
    public partial class _default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
             
        }

        protected void btnok_Click(object sender, EventArgs e)
        {
            string checkcode = "";
            //生成的验证码被保存到session中
            
            if (Session["CheckCode"] != null)

            {
                checkcode = Session["CheckCode"].ToString();

                if (this.txtyzm.Text != checkcode)
                {
                    Response.Write("<script type='text/javascript'>alert('验证码有误！')</script>");
                    lblyzm.Text = "验证码错误，请输入正确的验证码！";
                    lblyzm.Visible = true;

                    return;
                }              
            }        

           
            string strCn = "server=pc.hstc.cn;database=dhd2014112127;uid=2014112127;pwd=19950420";
            SqlConnection cn = new SqlConnection(strCn);
            cn.Open();
            string strsql = "select * from loading where username='" + this.txtName.Text + "'and password='" + this.txtpwd.Text + "'";
            SqlCommand cmd = new SqlCommand(strsql, cn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Session["username"] = dr["username"];
                Session["password"] = dr["password"];
                if (txtName.Text == Session["username"].ToString() && txtpwd.Text == Session["password"].ToString())

                    Response.Redirect("first.aspx");
            }
            else
            {
                lblcwxx.Text = "登录失败，请重新输入!";
            }
        }


        protected void btnfpwd_Click(object sender, EventArgs e)
        {
            Response.Redirect("passwordrecovery.aspx");
        }

        protected void btnfzc_Click(object sender, EventArgs e)
        {
            Response.Redirect("createuser.aspx");
        }

        protected void txtyzm_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
